package com.ganzalang.gmall.designpatterns.factory.methodfactory;

import lombok.extern.slf4j.Slf4j;

/**
 * @description: 不使用工厂方法
 * @author: ganzalang
 */
@Slf4j
public class WithoutMethodFactoryPatternDemo {

    public static void main(String[] args) {
        Product productA = new ProductAFactory().create();
        Product productB = new ProductBFactory().create();
        Product productC = new ProductCFactory().create();
        productA.execute();
        productB.execute();
        productC.execute();

    }

    public interface Product {
        void execute();
    }

    public static class ProductA implements Product {

        @Override
        public void execute() {
            log.info("执行A方法");
        }
    }

     public static class ProductB implements Product {

        @Override
        public void execute() {
            log.info("执行B方法");
        }
    }

     public static class ProductC implements Product {

        @Override
        public void execute() {
            log.info("执行C方法");
        }
    }

    public static class ProductAFactory {
        public Product create() {
            log.info("生产产品的通用逻辑，修改");
            log.info("生产产品A的特殊逻辑");
            return new ProductA();
        }
    }

    public static class ProductBFactory {
        public Product create() {
            log.info("生产产品的通用逻辑，修改");
            log.info("生产产品B的特殊逻辑");
            return new ProductB();
        }
    }

    public static class ProductCFactory {
        public Product create() {
            log.info("生产产品的通用逻辑，修改");
            log.info("生产产品C的特殊逻辑");
            return new ProductC();
        }
    }

}
